(********************************************************************)
(*	file: 		ADSPTalk.p											*)
(*	version:	.5alpha 											*)
(* 																	*)
(* Send information to an established connection.  The connection 	*)
(* previously have been established via the ADSPCALL xcmd.	If a 	*)
(* connection is not established, the timeout sequence will be 		*)
(* activated in the hopes that a connection is pending.				*)
(*																	*)
(* In:	params[1] =	name of the entity to talk to.					*)
(*		params[2] = message to send to that entity					*)
(*																	*)
(* ----------------------------------------------------------------	*)
(* By:		Donald Koscheka											*)
(* Date:	1-Mar-88												*)
(* 			©	Copyright 1988, Apple Computer, Inc.				*)
(*			All Rights Reserved										*)
(*																	*)
(* ----------------------------------------------------------------	*)
(*						Modification History						*)
(* ----------------------------------------------------------------	*)
(*  Date	| By	|	 				Description					*)
(* ----------------------------------------------------------------	*)
(*  1-Mar-88| DK	| file created									*)
(* 17-Mar-88| DK	| ALPHA RELEASE									*)
(* ----------------------------------------------------------------	*)
(********************************************************************)

(*******************************************************************
							Build Sequence

pascal -o "{hpo}"ADSPTalk.p.o "{adsp}"ADSPTalk.p
link -m ENTRYPOINT  -rt XCMD=1305 -sn Main=ADSPTalk¶
	"{hpo}"ADSPTalk.p.o¶
	"{libraries}"Interface.o ¶
	"{plibraries}"paslib.o¶
	-o "{hp}"HyperADSPTest
		 
*******************************************************************)


{$R-}
{$S ADSPTalk}
UNIT DummyUnit;

(*******************************************************************)
INTERFACE 
(*******************************************************************)


Uses MemTypes, QuickDraw, OSIntf, ToolIntf, PackIntf, HyperXCmd, AppleTalk, ADSP, adspxcmd;


Procedure EntryPoint( paramPtr : XCmdPtr );



(*******************************************************************)
IMPLEMENTATION
(*******************************************************************)


PROCEDURE ADSPTalk( paramPtr: XCmdPtr ); FORWARD;

Procedure EntryPoint( paramPtr : XCmdPtr );
	Begin
		ADSPTalk( paramPtr );
	End;
	
	
Procedure ADSPTalk( paramPtr : XCmdPtr );
VAR
	adsp		: ADSPPtr;
	error		: OSErr;
	eAddr		: AddrBlock;
	cb			: cbPtr;
	
{$I XCmdGlue.inc }
{$I XCMDADSP.inc }	

BEGIN
	error := noErr;
	adsp := ADSPPtr(RetrieveHandle( GLOBALDSPDATA ));
	IF(adsp <> NIL)AND(paramPtr^.params[1] <> NIL)AND(paramPtr^.params[2] <> NIL)THEN
		BEGIN
			adsp^.checkPoint := RECEIVING;
			{*** (1) Get the entity's address 			***}
			HLock( paramPtr^.params[1] );

			eAddr := NBPGetAddress( paramPtr^.params[1]^ );
			cb := adsp^.ends;
			
			IF LongInt( eAddr ) <> 0 THEN {*** (2) Find entity in connection list***}
				WHILE cb <> NIL DO
					IF (LongInt(cb^.adr)=LongInt(eAddr)) AND (cb^.ccb.state=sOpen) THEN	
						BEGIN
							error := DSPTalk(cb, paramPtr^.params[2] );
							cb := NIL;
						END
					ELSE
						cb := cb^.next;
							
			adsp^.checkPoint := CLOSE_OK;
			HUnlock( Handle(paramPtr^.params[1]) );
		END;
	paramPtr^.returnValue := ErrorReturn( error );
END;


end.
